
package qs.utils
{
	public class StringUtils
	{
		public static function trim(value:String):String
		{
			return value.match(/^\s*(.*?)\s*$/)[1];
		}
		public static function replaceAll(input:String, replace:String, replaceWith:String):String{
			if(input == null){
				return "";
			}else{
				input = new String(input);
				var s:Number = 0;
				s = input.search(replace);
				var t:String;
				while(input.indexOf(replace) >= 0){
					t = input.replace(replace, replaceWith);
					input = t
				}
				return input;
			}
		}
		/*public static function replaceAll(input:String, replace:String, replaceWith:String):String
		{
			//change to StringBuilder
			var sb:String = new String();
			var found:Boolean = false;

			var sLen:Number = input.length;
			var rLen:Number = replace.length;

			for (var i:Number = 0; i < sLen; i++)
			{
				if(input.charAt(i) == replace.charAt(0))
				{   
					found = true;
					for(var j:Number = 0; j < rLen; j++)
					{
						if(!(input.charAt(i + j) == replace.charAt(j)))
						{
							found = false;
							break;
						}
					}

					if(found)
					{
						sb += replaceWith;
						i = i + (rLen - 1);
						continue;
					}
				}
				sb += input.charAt(i);
			}
			//TODO : if the string is not found, should we return the original
			//string?
			return sb;
		}*/
	}
}